//
//  AFNTool.m
//  WinHonk
//
//  Created by 千叶妈 on 13-12-31.
//  Copyright (c) 2013年 he song. All rights reserved.
//

#import "AFNTool.h"

@implementation AFNTool

+(void)initYaoYues:(NSString *)path dic:(NSDictionary *)dic view:(UIView *)view success:(Success)Success failure:(Failure)Failure
{
    AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]init];
    manager.securityPolicy.allowInvalidCertificates = YES;
//         manager.requestSerializer = [AFJSONRequestSerializer serializer];
//    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager GET:path parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
            Success(responseObject);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            LOG(@"%@",error.localizedFailureReason);
            Failure(error);
        }];
    
    
}

+(void)initYaoYue:(NSString *)path dic:(NSDictionary *)dic view:(UIView *)view success:(Success)Success failure:(Failure)Failure
{
    AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]init];
    manager.securityPolicy.allowInvalidCertificates = YES;
//     manager.requestSerializer = [AFJSONRequestSerializer serializer];
    if (dic !=nil) {
       
        [manager POST:path parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
             Success(responseObject);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            
            
            Failure(error);
        }];
    }else
    {
        [manager GET:path parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
            Success(responseObject);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            
            Failure(error);
        }];

    }
    
}
+(void)tool:(NSURLRequest *)request success:(Success)Sucess failure:(Failure)failuer
{
    AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] init];
    [op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        Sucess(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failuer(error);
    }];
    [op start];
}
@end
